Stateful Traits
نویسندگان
چکیده
Traits offer a fine-grained mechanism to compose classes from reusable components while avoiding problems of fragility brought by multiple inheritance and mixins. Traits as originally proposed are stateless, that is, they contain only methods, but no instance variables. State can only be accessed within traits by accessors, which become required methods of the trait. Although this approach works reasonably well in practice, it means that many traits, viewed as software components, are artificially incomplete, and classes that use such traits may contain significant amounts of boilerplate glue code. Although these limitations are largely mitigated by proper tool support, we seek a cleaner solution that supports stateful traits. The key difficulty is how to handle conflicts that arise when composed traits contribute instance variables whose names clash. We present a solution that is faithful to the guiding principle of stateless traits: the client retains control of the composition. Stateful traits consist of a minimal extension to stateless traits in which instance variables are purely local to the scope of a trait, unless they are explicitly made accessible by the composing client of a trait. Naming conflicts are avoided, and variables of disjoint traits can be explicitly merged by clients. We discuss and compare two implementation strategies, and briefly present a case study in which stateful traits have been used to refactor the trait-based version of the Smalltalk collection hierarchy.
منابع مشابه
Stateful traits and their formalization
Traits offer a fine-grained mechanism to compose classes from reusable components while avoiding problems of fragility brought by multiple inheritance and mixins. Traits as originally proposed are stateless, that is, they contain only methods, but no instance variables. State can only be accessed within stateless traits by accessors, which become required methods of the trait. Although this app...
متن کاملAdding State and Visibility Control to Traits Using Lexical Nesting
Traits are reusable building blocks that can be explicitly composed to share methods across unrelated class hierarchies. In their original form, traits do not contain state and cannot express visibility control for methods. Two extensions, stateful traits and freezable traits, have been proposed to overcome these limitations. However, these extensions introduce complexity and have not yet been ...
متن کاملExtending FeatherTrait Java with Interfaces
In the context of Featherweight Java by Igarashi, Pierce, and Wadler, and its recentextension FeatherTrait Java (FTJ) by the authors, we investigate classes that can beextended with trait composition. A trait is a collection of methods, i.e., behaviorswithout state; it can be viewed as an “incomplete stateless class” i.e., an interfacewith some already written behavior. Traits c...
متن کاملRealizing Stateful Public Key Encryption in Wireless Sensor Network
In this paper, we present our implementation of a stateful public key encryption (stateful PKE) scheme in the wireless sensor network (WSN) environment. In order to reduce the communication overhead of the stateful PKE scheme we implement, which is of prime importance in WSN, we introduce a technique called “indexing”. The performance analysis of our implementation shows that there are signific...
متن کاملTowards A Stateful Analysis Framework for Smart Grid Network Intrusion Detection
Cybersecurity is a primary issue in the development of smarter grid systems. Smart grid systems utilize a number of application protocols in order to implement their devices and services, and the information in the application protocols is useful for intrusion detection which is one of major security solutions. Stateful analysis based intrusion detection monitors network and system behaviours a...
متن کامل